<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>采购订单入库单产品对比</title>
    <script type="text/javascript">
      Ext.onReady(function(){

        var vendorTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{number}|{name}', '</div></tpl>');
        var vendorStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/vendor/getAllVendors?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            }, {
              name: 'name'
            }])
        });

        var vendor =  new Ext.form.ComboBox({
          fieldLabel: '供应商',
          store: vendorStore,
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'vendor_id',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '95%',
          //hideTrigger: false,
          tpl: vendorTemplate,
          minChars: 0,
          itemSelector: 'div.search-item',
          triggerAction: 'all',
          editable:false,
          selectOnFocus:true
        });

        var purchaseOrderNumber = new Ext.form.TextField({
          fieldLabel: '采购单号',
          name: 'purchase_order_number',
          anchor: '95%'
        });

        var stateStore = new Ext.data.ArrayStore({
          fields: ['text','value'],
          data : auditStatusArray
        });

        var auditingStatus = new Ext.form.ComboBox({
          fieldLabel: '审批状态',
          store: stateStore,
          displayField:'text',
          typeAhead: true,
          anchor: '95%',
          mode: 'local',
          name: 'auditing_status',
          forceSelection: true,
          triggerAction: 'all',
          editable:false,
          valueField: 'value',
          emptyText:'',
          selectOnFocus:true
        })

        var beginDate = new Ext.form.DateField({
          fieldLabel: '到货日期',
          name: 'begin_date',
          id: 'e_begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          inputType: '2010-01-01',
          anchor: '95%',
          vtype: 'daterange',
          endDateField: 'e_end_date'
        });

        var endDate = new Ext.form.DateField({
          fieldLabel: '至    ',
          name: 'end_date',
          id: 'e_end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          inputType: '2010-01-01',
          anchor: '95%',
          vtype: 'daterange',
          startDateField: 'e_begin_date'
        });

        var showEntryInfo = new Ext.form.Checkbox({
          name: 'entry_info',
          clearCls: 'allow-float',
          itemCls: 'float-left',
          fieldLabel: '显示入库明细'
        })
        
        var submitButton = new Ext.Button({
          text: '搜索',
          iconCls: 'finding',
          handler: function(){
            if (queryFormPanel.form.isValid()) {
              productBalanceDS.removeAll();
              productBalanceDS.baseParams.purchase_order_number = purchaseOrderNumber.getValue();
              productBalanceDS.baseParams.auditing_status = auditingStatus.getValue();

              productBalanceDS.baseParams.begin_date = beginDate.getRawValue();
              productBalanceDS.baseParams.end_date = endDate.getRawValue();
              productBalanceDS.baseParams.vendor_id = vendor.getValue();
              productBalanceDS.baseParams.entry_info = showEntryInfo.getValue();
              productBalanceDS.load();
            }
          }
        });

        var clearButton = new Ext.Button({
          text: '清空',
          width:50,
          handler: function(){
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = new Ext.form.FormPanel({
          //baseCls: 'x-plain',
          //renderTo: 'query_form',
          labelWidth: 85,
          width: screenWidth-175,
          labelAlign: 'right',
          frame : true,
          border:false,
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1100},
              title: '查询条件',
              border: true,
              items: [{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: .2,
                      layout: 'form',
                      border: false,
                      items: [purchaseOrderNumber]
                    }, {
                      columnWidth: .2,
                      layout: 'form',
                      border: false,
                      items: [auditingStatus]
                    }, {
                      columnWidth: .4,
                      layout: 'form',
                      border: false,
                      items: [vendor]
                    }]
                },{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: .2,
                      layout: 'form',
                      border: false,
                      items: [beginDate]
                    }, {
                      columnWidth: .2,
                      layout: 'form',
                      border: false,
                      items: [endDate]
                    },{
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [showEntryInfo]
                    }, {
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [submitButton]
                    }, {
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [clearButton]
                    }]
                }]
            }]
        });
        //显示采购订单操作时的窗口介面。
        //----------------------------------采购订单Grid-------------------------
        //采购订单Grid Store
        var productBalanceDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: pageSize
          },
          proxy: new Ext.data.HttpProxy({
            url: '/purchase_order/getProductNeedEntry'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'auditing_status'
            },{
              name: 'entry_order_number'
            },{
              name: 'purchase_order_number'
            },{
              name: 'product_name'
            },{
              name: 'product_number'
            },{
              name: 'purchase_quantity'
            }, {
              name: 'action_date'
            }, {
              name: 'auditing_status'
            }, {
              name: 'vendor_name'
            }, {
              name: 'department_name'
            } ,{
              name: 'entry_quantity',
              type: 'int'
            }, {
              name: 'store_status'
            }])
        });

        //生成采购订单Grid的CM
        var productBalanceCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),{
              id: 'common',
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '采购订单单号',
              dataIndex: 'purchase_order_number',
              width: 170
            },{
              header: '采购订单状态',
              dataIndex: 'auditing_status',
              renderer: auditingStatusRender,
              width: 90
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 90
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '产品编号',
              dataIndex: 'product_number',
              width: 80
            },{
              header: '采购数量',
              dataIndex: 'purchase_quantity',
              align:'right',
              width: 75
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              width: 60,
              renderer: auditingStatusRender
            },{
              header: '发货日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),
              width: 75
            },{
              header: '入库单单号',
              dataIndex: 'entry_order_number',
              width: 120
            },{
              header: '入库数量',
              dataIndex: 'entry_quantity',
              align:'right',
              width: 75
            },{
              header: '入库状态',
              dataIndex: 'store_status',
              renderer: dealWithStatusRender,
              width: 70
            }
          ]});

        //生成要订单的产品的Grid
        var productBalanceGrid = new Ext.grid.GridPanel({
          title:'采购订单与入库单对比列表',
          store: productBalanceDS,
          cm: productBalanceCM,
          loadMask: true,
          width: screenWidth-175,
          height: screenHeight-375,
          frame: true,
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
          bbar: new Ext.PagingToolbar({
            pageSize: pageSize,
            store: productBalanceDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })          
        });    

        //总的panel
        var workbenchPanel = new Ext.Panel({
          width: screenWidth-175,
          height: screenHeight-265,
          frame:false,
          layout:'table',
          layoutConfig: {columns:1},
          defaults:{margins:'5 5 5 5'},
          items:[queryFormPanel,productBalanceGrid]
        });
        workbenchPanel.render("product_need_entry_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="product_need_entry_workbench_panel"></div>
  </body>
</html>